<?php

require_once 'user.class.php';

class Controller {

    public static function login($u_username, $u_password) {
        $rs = new User(null, null, null, null, null);
        if ($u_username != NULL && $u_password != NULL) {
            /// Lets transfer password into md5
            $u_password = md5($u_password);

            /// Connecting to MySQL and Selecting database
            $con = mysql_connect("ltuprj.qv.vic.edu.au", "Cerberus", "mEtaekdT") or die(mysql_error());

            if (!$con) {
                die('Could not connect: ' . mysql_error());
            }
			$sql = "SELECT userID, loginName, userName, emailAddress FROM `C-dev`.USER Where loginName = '$u_username' AND userPass = '$u_password';";
            $result = mysql_query($sql, $con);
            
            //$num=mysql_num_rows($query);
            $row = mysql_fetch_row($result);
            print_r($row);
			mysql_free_result($result);

            if ($row != null) {
                $rs->set_ID($row[0]);
                $rs->set_user_login($row[1]);
                $rs->set_user_fullname($row[2]);
                $rs->set_user_email($row[3]);
            } else {
                $rs = null;
            }

            mysql_close($con);
        }

 
        return $rs;
    }
}
    
?>